home *** CD-ROM | disk | FTP | other *** search
- unit OrdForm;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, TypInfo;
-
- type
- TForm1 = class(TForm)
- Listbox1: TListBox;
- ListBox2: TListBox;
- Label1: TLabel;
- procedure Listbox1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- procedure AddType (pti: PTypeInfo);
- procedure AddToList (S: String);
- end;
-
- procedure ShowOrdinal (pti: PTypeInfo; sList: TStrings);
- procedure ListEnum (pti: PTypeInfo; sList: TStrings);
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure TForm1.Listbox1Click(Sender: TObject);
- var
- pti: PTypeInfo;
- begin
- pti := PTypeInfo (ListBox1.Items.Objects [
- Listbox1.ItemIndex]);
- ListBox2.Items.Clear;
- ShowOrdinal (pti, ListBox2.Items);
-
- // special case: TColor
- if ListBox1.Items [ListBox1.ItemIndex] = 'TColor' then
- begin
- ListBox2.Items.Add ('');
- ListBox2.Items.Add ('Values...');
- GetColorValues (AddToList);
- end;
-
- // special case: TCursor
- if ListBox1.Items [ListBox1.ItemIndex] = 'TCursor' then
- begin
- ListBox2.Items.Add ('');
- ListBox2.Items.Add ('Values...');
- GetCursorValues (AddToList);
- end;
- end;
-
- procedure TForm1.AddToList (S: String);
- begin
- ListBox2.Items.Add (S);
- end;
-
- // show RTTI information for ordinal types
- procedure ShowOrdinal (pti: PTypeInfo; sList: TStrings);
- var
- ptd: PTypeData;
- begin
- // protect against misuse
- if not (pti^.Kind in [tkInteger, tkChar,
- tkEnumeration, tkSet, tkWChar]) then
- raise Exception.Create ('Invalid type information');
-
- // get a pointer to the TTypeData structure
- ptd := GetTypeData (pti);
-
- // access the TTypeInfo structure
- sList.Add ('Type Name: ' + pti^.Name);
- sList.Add ('Type Kind: ' + GetEnumName (
- TypeInfo (TTypeKind),
- Integer (pti^.Kind)));
-
- // access the TTypeData structure
- sList.Add ('Implement: ' + GetEnumName (
- TypeInfo (TOrdType),
- Integer (ptd^.OrdType)));
-
- // a set has no min and max
- if pti^.Kind <> tkSet then
- begin
- sList.Add ('Min Value: ' + IntToStr (ptd^.MinValue));
- sList.Add ('Max Value: ' + IntToStr (ptd^.MaxValue));
- end;
-
- // add the enumeration base type
- // and the list of the values
- if pti^.Kind = tkEnumeration then
- begin
- sList.Add ('Base Type: ' + (ptd^.BaseType)^.Name);
- sList.Add ('');
- sList.Add ('Values...');
- ListEnum (pti, sList);
- end;
-
- // show RRTI info about set base type
- if pti^.Kind = tkSet then
- begin
- sList.Add ('');
- sList.Add ('Set base type information...');
- ShowOrdinal (ptd^.CompType, sList);
- end;
- end;
-
- procedure ListEnum (pti: PTypeInfo; sList: TStrings);
- var
- I: Integer;
- begin
- with GetTypeData(pti)^ do
- for I := MinValue to MaxValue do
- sList.Add (' ' + IntToStr (I) + '. ' +
- GetEnumName (pti, I));
- end;
-
- procedure TForm1.AddType (pti: PTypeInfo);
- begin
- ListBox1.Items.AddObject(pti^.Name, TObject (pti))
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- AddType (TypeInfo (Boolean));
- AddType (TypeInfo (Byte));
- AddType (TypeInfo (Char));
- AddType (TypeInfo (Integer));
- AddType (TypeInfo (LongInt));
- AddType (TypeInfo (ShortInt));
- AddType (TypeInfo (SmallInt));
- AddType (TypeInfo (WChar));
- AddType (TypeInfo (Word));
- AddType (TypeInfo (Cardinal));
- AddType (TypeInfo (TAlignment));
- AddType (TypeInfo (TComponentState));
- AddType (TypeInfo (TComponentStyle));
- AddType (TypeInfo (THelpContext));
- AddType (TypeInfo (TOperation));
- AddType (TypeInfo (TShiftState));
- AddType (TypeInfo (TThreadPriority));
- AddType (TypeInfo (TAlign));
- AddType (TypeInfo (TControlState));
- AddType (TypeInfo (TControlStyle));
- AddType (TypeInfo (TCursor));
- AddType (TypeInfo (TDragMode));
- AddType (TypeInfo (TDragState));
- AddType (TypeInfo (TImageType));
- AddType (TypeInfo (TMouseButton));
- AddType (TypeInfo (TResType));
- AddType (TypeInfo (TTabOrder));
- AddType (TypeInfo (TBorderIcons));
- AddType (TypeInfo (TBorderStyle));
- AddType (TypeInfo (TCloseAction));
- AddType (TypeInfo (TFormBorderStyle));
- AddType (TypeInfo (TFormStyle));
- AddType (TypeInfo (TModalResult));
- AddType (TypeInfo (TPosition));
- AddType (TypeInfo (TPrintScale));
- AddType (TypeInfo (TScrollBarInc));
- AddType (TypeInfo (TScrollBarKind));
- AddType (TypeInfo (TTileMode));
- AddType (TypeInfo (TWindowState));
- AddType (TypeInfo (TBrushStyle));
- AddType (TypeInfo (TColor));
- AddType (TypeInfo (TFillStyle));
- AddType (TypeInfo (TFontPitch));
- AddType (TypeInfo (TFontStyles));
- AddType (TypeInfo (TPenMode));
- AddType (TypeInfo (TPenStyle));
- AddType (TypeInfo (TCheckBoxState));
- AddType (TypeInfo (TComboBoxStyle));
- AddType (TypeInfo (TEditCharCase));
- AddType (TypeInfo (TListBoxStyle));
- AddType (TypeInfo (TScrollCode));
- AddType (TypeInfo (TScrollStyle));
- end;
-
- end.
-